package com.android.clinic.app.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.clinic.app.R;
import com.android.clinic.app.entity.ReportInfo;
import com.android.clinic.app.glide.ImageLoaderUtils;
import com.android.clinic.app.utils.DisplayUtil;
import com.android.clinic.app.utils.Utils;

/**
 * Created by cheng on 2018/7/17.
 */
public class ReportAdapter extends BaseListAdapter<ReportInfo> {

    public ReportAdapter(Context context) {
        super(context, R.layout.item_list_report);
    }

    @Override
    protected Object setupViewHolder(@Nullable View convertView, ViewGroup parent, int typeIndex) {
        return new ViewHolder(convertView);
    }

    @Override
    protected void setupBindViewHolder(final ReportInfo object, Object viewHolder, int position, int typeIndex) {
        ViewHolder holder = (ViewHolder) viewHolder;
        holder.tvTitle.setText(!Utils.isEmpty(object.getTitle()) ? Utils.getSubStringTitle(object.getTitle()) : "--");
        holder.tvContent.setText(!Utils.isEmpty(object.getContent()) ? object.getContent() : "--");
        holder.tvTime.setText(Utils.getFormatTime(object.getConnectTime()));

        if (!Utils.isEmpty(object.getImageUrl())) {
            String[] imageArray = object.getImageUrl().split(",");
            ImageLoaderUtils.getInstance().loadNormalImageWithReport(imageArray[0], holder.ivPic,
                    DisplayUtil.dip2px(100), DisplayUtil.dip2px(75));
        } else {
            ImageLoaderUtils.getInstance().loadNormalImageWithReport("", holder.ivPic,
                    DisplayUtil.dip2px(100), DisplayUtil.dip2px(75));
        }
    }

    class ViewHolder extends BaseViewHolder {

        ImageView ivPic;
        TextView tvTitle, tvContent, tvTime;

        public ViewHolder(View itemView) {
            super(itemView);
            ivPic = (ImageView) itemView.findViewById(R.id.iv_pic);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
            tvContent = (TextView) itemView.findViewById(R.id.tv_content);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }

}
